package com.rs.game.npc.glacor;

import com.rs.game.Hit;
import com.rs.game.WorldTile;
import com.rs.game.npc.NPC;
import com.rs.game.npc.glacor.Glacor;

public class EnduringMinion extends NPC {

	private static final long serialVersionUID = 6520218487867695493L;

	public Glacor parent;
	public static boolean defeated = false;

	public EnduringMinion(int id, WorldTile tile, int mapAreaNameHash,
			boolean canBeAttackFromOutOfArea, boolean spawned, Glacor parent) {
		super(id, tile, mapAreaNameHash, canBeAttackFromOutOfArea, spawned);
		this.parent = parent;
	}

	@Override
	public void processEntity() {
		super.processEntity();

		if (getHitpoints() <= 0 || isDead()) {
			if (!defeated)
			defeated = true;
		}
	}
	
	@Override
	public void handleIngoingHit(final Hit hit) {
		int distanceX = getX() - parent.getX();
		int distanceY = getY() - parent.getY();
		if (distanceX < 1 && distanceY < 1) {
			hit.setDamage((int) (hit.getDamage() * 0.20));
			return;
		} else if (distanceX < 2 && distanceY < 2) {
			hit.setDamage((int) (hit.getDamage() * 0.40));
			return;
		} else if (distanceX < 3 && distanceY < 3) {
			hit.setDamage((int) (hit.getDamage() * 0.60));
			return;
		} else if (distanceX < 4 && distanceY < 4) {
			hit.setDamage((int) (hit.getDamage() * 0.80));
			return;
		} else {
			hit.setDamage(hit.getDamage());
			return;
		}
	}

}